package br.edu.ifrn.model;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

@Entity
public class Metavalor implements Serializable{
	@Id
	@SequenceGenerator(name = "seq_metavalor", sequenceName = "seq_metavalor", allocationSize = 1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_metavalor")
	private Long id;
	@ManyToOne
	@JoinColumn(name="fk_metadado")
	private Metadado metadado;
	private String valor;	
	
	public Metavalor() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Metavalor(Metadado metadado, String valor) {
		super();
		this.metadado = metadado;
		this.valor = valor;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Metadado getMetadado() {
		return metadado;
	}

	public void setMetadado(Metadado metadado) {
		this.metadado = metadado;
	}

	public String getValor() {
		return valor;
	}

	public void setValor(String valor) {
		this.valor = valor;
	}
	
	public Date getValor2() {
		Date date = new Date(); 
		DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");  
        try {
			date = formatter.parse(valor);
		} catch (ParseException e) {
			//e.printStackTrace();
		}  		
		return date;
	}

	public void setValor2(Date valor) {
		DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");  
        try {
			this.valor = formatter.format(valor); 
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	
}
